package controller.login;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import utils.LoggerUtil;

@Controller(value = "/logowanie.html")
public class FormularzLogowaniaController {
	private final Logger log = Logger.getLogger(getClass());

	@RequestMapping(method = RequestMethod.GET)
	protected String showForm(HttpServletRequest request, Model model, @RequestParam(value = "error", required = false, defaultValue = "false") boolean error) {
		if(request.getSession().getAttribute("loggedUser")!=null){
			return "redirect:/index.html";
		}
		log.info(LoggerUtil.getUserInfo(request));
		log.info("Wyswietlenie formularza logowania");
		model.addAttribute("isError", error);
		return "common/logonForm";
	}

}
